# Use an official Python runtime as a parent image
FROM python:2.7-slim

# 覆盖原文件
ADD sources.list /etc/apt/sources.list

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in requirements.txt
# RUN pip install --trusted-host pypi.python.org -i https://pypi.doubanio.com/simple/module_name -r requirements.txt
RUN pip install -i https://pypi.doubanio.com/simple/ -r requirements.txt

# Make port 80 available to the world outside this container
EXPOSE 80

# Define environment variable
ENV NAME World

# Run app.py when the container launches
CMD ["python", "app.py"]

# 实践1
# 创建虚拟机default
# docker-machine create --driver virtualbox default
# 初始化客户端的环境为default，按照说明操作
# docker-machine env default
# 创建镜像hello-world
# docker build -t lizhen/hello-world:latest .
# 运行镜像
# docker run -d -p 4000:80 lizhen/hello-world:latest

# 实践2
# 创建虚拟机default
# docker-machine create --driver virtualbox default
# 初始化客户端的环境为default，按照说明操作
# docker-machine env default
# 创建镜像hello-world
# docker build -t lizhen/hello-world:latest .
# 使用redis
# docker-machine ssh default "mkdir ./data"
# 初始化集群
# docker swarm init --advertise-addr 192.168.99.100:2376
# 创建stack
# docker stack deploy --with-registry-auth -c docker-compose.yml hello-stack 

# 实践3
# 创建虚拟机default
# docker-machine create --driver virtualbox default
# 初始化客户端的环境为default，按照说明操作
# docker-machine env default
# 创建镜像hello-world
# docker build -t lizhen/hello-world:latest .
# 使用redis
# docker-machine ssh default "mkdir ./data"
# 初始化集群
# docker swarm init --advertise-addr 192.168.99.100:2376
# 修改镜像源
# sudo vi /var/lib/boot2docker/profile
# 在--label provider=virtualbox的下一行添加--registry-mirror https://xxxxxxxx.mirror.aliyuncs.com
# sudo /etc/init.d/docker restart 或者 exit退出VM bash，在Windows命令行中执行docker-machine restart
# 下载registry镜像
# sudo docker pull registry
# 创建目录
# sudo mkdir -p /opt/data/registry
# 启动私有仓库
# sudo docker run -d -p 8888:5000 -v /opt/data/registry:/var/lib/registry --name private_repo registry
# 修改镜像源
# sudo vi /var/lib/boot2docker/profile
# 在--registry-mirror https://xxxxxxxx.mirror.aliyuncs.com的下一行添加--insecure-registry 192.168.99.100:8888
# sudo /etc/init.d/docker restart 或者 exit退出VM bash，在Windows命令行中执行docker-machine restart
# tag镜像
# docker tag lizhen/hello-world:latest 192.168.99.100:8888/hello-world
# push镜像
# docker push 192.168.99.100:8888/hello-world
# 创建虚拟机myvm1
# docker-machine create --driver virtualbox myvm1
# 初始化客户端的环境为myvm1，按照说明操作
# docker-machine env myvm1
# 虚拟机myvm1使用redis
# docker-machine ssh myvm1 "mkdir ./data"
# 虚拟机myvm1加入集群master(监听端口为2377)的worker节点
# docker swarm join -token new_token 192.168.99.100:2377
# 修改镜像源
# sudo vi /var/lib/boot2docker/profile
# 在--label provider=virtualbox的下一行添加--registry-mirror https://xxxxxxxx.mirror.aliyuncs.com
# 在--registry-mirror https://xxxxxxxx.mirror.aliyuncs.com的下一行添加--insecure-registry 192.168.99.100:8888
# sudo /etc/init.d/docker restart 或者 exit退出VM bash，在Windows命令行中执行docker-machine restart
# 初始化客户端的环境为default，按照说明操作
# docker-machine env default
# 创建stack
# docker stack deploy --with-registry-auth -c docker-compose.yml hello-stack